<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>注册</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<link rel="stylesheet" href="./zhuce.css" type="text/css">
    <script src="./jquery-2.1.0.js"></script>   
  </head>
  
  <body>
<form id="form"  name="form2" action="Zhuceservlet"  method="post">
    <table id="table_zhu"  >
        <tr>
            <td></td> <td id="ti">欢迎注册知识管理系统</td>
        </tr>
        <tr>
            <th class="t1">账号：</th><td><input type="text" id="username" class="text"  name="userid"></td>
            <td id="show" style="width: 100px; position: relative;left: -80px;"></td>
        </tr>
        <tr>
            <td class="zhu"></td> <td class="zhu">请输入4到16位（字母，数字，下划线，减号）用户名</td>
        </tr>
        <tr>
            <th class="t1">密码：</th><td><input type="password" id="pwd1" class="text" name="password"></td>
        </tr>
        <tr>
            <td class="zhu"></td> <td class="zhu">密码由6-21字母和数字组成，不能是纯数字或纯英文</td>
        </tr>
        <tr>
            <th class="t1">确认密码：</th><td><input type="password" id="pwd2" class="text" ></td>
        </tr>
        <tr>
            <td class="zhu"></td> <td class="zhu">输入相同的密码</td>
        </tr>
        <tr>
        <th class="t1">邮箱：</th> <td><input type="text" id="email" class="text"  name="email"></td>
        </tr>
        <tr>
            <td class="zhu"></td> <td class="zhu">请输入合法的邮箱</td>
        </tr>
        <tr>
            <th colspan="2"><input type="button" id="bot1" value="注册" class="b1"  />
                <input type="reset" value="重写"class="b1"></th>
        </tr>
    </table>
    <a href="MyJsp.jsp">回到主页</a>
</form>


    <script>
    $(function(){
    	$("#username").blur(function(){
    		var username=$("#username").val();
    		$.ajax({
    			type:"get",
    	 		url: "./Yanservlet?name="+username,
    	 		dataType: "text",
    	 		success: function(data){//success：成功后->callback        
                 //        动作标签:function(参数列表){} ->onClick:function(参数列表){}
                 console.log("success");
                 
                     if(data=="true"){
                        $("#show").html("ok");
                     }else if(data=="false"){
                        $("#show").html("用户名已存在");
                    }
                 },
                 error: function(){//4.error 失败的回调方法
                 console.log("error");
                     $("#show").html("Error XMLHttpRequest");
                 }
    		});
    	});
    	$("#bot1").click(function () {
            var username=$("#username").val();
            var pwd1=$("#pwd1").val();
            var pwd2=$("#pwd2").val();
            var email=$("#email").val();
            //用户名正则，4到16位（字母，数字，下划线，减号）
            var un = /^[a-zA-Z0-9_-]{4,16}$/;

            //密码由6-21字母和数字组成，不能是纯数字或纯英文
            var pwds = /^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,21}$/;

          
            var emails=/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/ ;

            if(!$("#show").val()=="ok"){
                alert("要输入合法用户名哦！");
            }else if(!pwds.test(pwd1)){
                alert("密码不合法辣");
            }else if(pwd2!=pwd1){
                alert("两次输入密码不一样哟！");
            }else if(!emails.test(email)){
                alert("邮箱输入不合法！");
            }else {
                $("#form").submit();
            }

        });
    });
        


    </script>

</body>
</html>
